/*
 * @Author: yangzonglong
 * @Date: 2021-02-22 14:45:41
 * @version: v1.0.0
 * @Descripttion: 配置信息
 * @LastEditors: 871387321@qq.com 871387321@qq.com
 * @LastEditTime: 2023-11-14 15:08:34
 * @Auditor:
 */
import uuidv4 from 'uuid-v4';
import Input from './components/input/Input';
import Code from './components/code/Code';
import InputNumber from './components/inputNumber/InputNumber';
import DatePicker from './components/datePicker/DatePicker';
import Select from './components/select/Select';
import Radio from './components/radio/Radio';
import Text from './components/text/Text';
import TextArea from './components/textarea/Textarea';
import Checkbox from './components/checkbox/Checkbox';
import Switch from './components/switch/Switch';
import Upload from './components/upload/Upload';
import Table from './components/table/Table';
import DividLine from './components/dividLine/DividLine';
import AdjustSpacing from './components/adjustSpacing/AdjustSpacing';
import Img from './components/img/Img';
import DataLink from './components/dataLinkLov/DataLinkLov';
import DataLinkComBox from './components/dataLinkComBox/DataLinkComBox';
import Media from './components/media/Media';
import RichText from './components/richText/RichText';
import ScriptChange from './components/scriptChange/ScriptChange';
import ScriptLoad from './components/scriptLoad/ScriptLoad';
import ScriptBefore from './components/scriptBefore/ScriptBefore';
import ScriptSubmit from './components/scriptSubmit/ScriptSubmit';
import OrderNumber from './components/orderNumber/OrderNumber';
import DataList from './components/dataList/DataList';
import Button from './components/Button/Button';
import Template from './components/template/Template';
import ScriptInterceptors from './components/scriptInterceptors/ScriptInterceptors';
import Scan from './components/scan/Scan';
import Row from './components/row/Row';
import Col from './components/col/Col';
import Tabs from './components/tabs/Tabs';
import Charts from './components/charts/Charts';
import Collapse from './components/collapse/Collapse';
import Tag from './components/tag/Tag';

import InputController from './components/input/InputController';
import CodeController from './components/code/CodeController';
import InputNumberController from './components/inputNumber/InputNumberController';
import DatePickerController from './components/datePicker/DatePickerController';
import SelectController from './components/select/SelectController';
import RadioController from './components/radio/RadioController';
import TextController from './components/text/TextController';
import TextareaController from './components/textarea/TextareaController';
import CheckboxController from './components/checkbox/CheckboxController';
import SwitchControl from './components/switch/SwitchControl';
import UploadController from './components/upload/UploadController';
import TableController from './components/table/TableController';
import DividLineController from './components/dividLine/DividLineController';
import AdjustSpacingController from './components/adjustSpacing/AdjustSpacingController';
import ImgController from './components/img/ImgController';
import DataLinkController from './components/dataLinkLov/DataLinkLovController';
import DataLinkComBoxController from './components/dataLinkComBox/DataLinkComBoxController';
import MediaController from './components/media/MediaController';
import RichTextController from './components/richText/RichTextController';
import ScriptChangeController from './components/scriptChange/ScriptChangeController';
import ScriptLoadController from './components/scriptLoad/ScriptLoadController';
import ScriptBeforeController from './components/scriptBefore/ScriptBeforeController';
import ScriptSubmitController from './components/scriptSubmit/ScriptSubmitController';
import OrderNumberController from './components/orderNumber/OrderNumberController';
import DataListController from './components/dataList/DataListController';
import ButtonController from './components/Button/ButtonController';
import TemplateController from './components/template/TemplateController';
import ScriptInterceptorsController from './components/scriptInterceptors/ScriptInterceptorsController';
import ScanController from './components/scan/ScanController';
import ColController from './components/col/ColController';
import RowController from './components/row/RowController';
import TabsControl from './components/tabs/TabsControl';
import ChartsController from './components/charts/ChartsController';
import CollapseController from './components/collapse/CollapseController';
import TagController from './components/tag/TagController';

const T = window.$app.t;

export const dragDirectionMap = {
  UP: 'up',
  DOWN: 'down',
};

export const dragSourceMap = {
  CANVAS: 'canvas',
  MENU: 'menu',
  NONE: '',
};

export const ControlType = {
  TEXT: 'text',
  ROW: 'row',
  COL: 'col',
  INPUT: 'input',
  INPUT_NUMBER: 'inputNumber',
  DATE_PICKER: 'datePicker',
  SELECT: 'select',
  RADIO: 'radio',
  CHECKBOX: 'checkbox',
  TEXT_AREA: 'textArea',
  SWITCH: 'switch',
  UPLOAD: 'upload',
  TABLE: 'table',
  DIVIDLINE: 'dividLine',
  ADJUSTSPACING: 'adjustSpacing',
  IMG: 'img',
  DATALINK: 'dataLink',
  DATALINKCOMBOX: 'dataLinkComBox',
  MEDIA: 'media',
  RICHTEXT: 'richtext',
  SCRIPT_CHANGE: 'onChange',
  SCRIPT_LOAD: 'onLoad',
  SCRIPT_SUBMIT: 'onSubmit',
  SCRIPT_INTERCEPTORS: 'interceptors',
  SCRIPT_BEFORE: 'before',
  ORDER_NUMBER: 'orderNumber',
  DATA_LIST: 'dataList',
  BUTTON: 'button',
  MODELFORM: 'modelform',
  MODELTABLE: 'modeltable',
  TEMPLATE: 'template',
  CODE: 'code',
  SCAN: 'scan',
  CHARTS: 'charts',
  TABS: 'tabs',
  COLLAPSE: 'collapse',
  TAG: 'tag'
};

export const menus = [
  {
    title: T('baseComponent'),
    children: [
      {
        title: T('singleLineText'),
        type: ControlType.INPUT,
        icon: 'input',
        desc: '单行文本输入框，需要填写者在输入框内根据标题填写相应内容',
      },
      {
        title: T('scanningElement'),
        type: ControlType.SCAN,
        icon: 'input',
        desc: '扫码',
      },
      {
        title: T('singleDigit'),
        type: ControlType.INPUT_NUMBER,
        icon: 'number',
        desc: '单行数字输入框',
      },
      {
        title: T('multilineInput'),
        type: ControlType.TEXT_AREA,
        icon: 'textArea',
      },
      {
        title: T('toggle'),
        type: ControlType.SWITCH,
        icon: 'switch',
      },
      {
        title: T('dateElement'),
        type: ControlType.DATE_PICKER,
        icon: 'date',
        desc: '时间选择组件，需要填写者选择具体日期时间',
      },
      {
        title: T('singleChoice'),
        type: ControlType.RADIO,
        icon: 'radio',
      },
      {
        title: T('multipleChoice'),
        type: ControlType.CHECKBOX,
        icon: 'checkbox',
      },
      {
        title: T('dropDownSelection'),
        type: ControlType.SELECT,
        icon: 'select',
      },

      {
        title: T('attachmentUpload'),
        type: ControlType.UPLOAD,
        icon: 'upload',
      },
      {
        title: T('picture'),
        type: ControlType.IMG,
        icon: 'img',
      },
      {
        title: T('buttonElement'),
        type: ControlType.BUTTON,
        icon: 'button'
      },
      {
        title: T('twoDimensionalCode'),
        type: ControlType.CODE,
        icon: 'code',
      },
    ],
  },
  {
    title: T('highLevelComponent'),
    children: [
      { title: T('descriptionText'), type: ControlType.TEXT, icon: 'text', desc: '描述文字可以为表单添加段落说明信息，字体样式可自定义设置' },
      { title: T('table'), type: ControlType.TABLE, icon: 'table' },
      { title: T('tag'), type: ControlType.TAG, icon: 'tag' },
      { title: T('lovCorrelation'), type: ControlType.DATALINK, icon: 'link' },
      { title: T('comBoxAssociation'), type: ControlType.DATALINKCOMBOX, icon: 'linkComBox' },
      { title: T('multimedia'), type: ControlType.MEDIA, icon: 'media' },
      { title: T('richText'), type: ControlType.RICHTEXT, icon: 'richtext' },
      { title: T('flowNumber'), type: ControlType.ORDER_NUMBER, icon: 'odNum' },
      { title: T('dataList'), type: ControlType.DATA_LIST, icon: 'dataList' },
      { title: T('modelForm'), type: ControlType.MODELFORM, icon: 'modelToForm' },
      { title: T('modelList'), type: ControlType.MODELTABLE, icon: 'modelToForm' },
      { title: T('templateEngine'), type: ControlType.TEMPLATE, icon: 'artTemplate' },
      { title: T('TAB'), type: ControlType.TABS, icon: 'artTemplate' },
      { title: T('collapse'), type: ControlType.COLLAPSE, icon: 'collapse' },
    ],
  },
  {
    title: T('chartComponent'),
    children: [
      { title: T('echartsDiagram'), type: ControlType.CHARTS, icon: 'artTemplate' },
    ],
  },
  {
    title: T('layoutComponent'),
    children: [
      { title: T('row'), type: ControlType.ROW, icon: 'row' },
      { title: T('column'), type: ControlType.COL, icon: 'col' },
      { title: T('partingLine'), type: ControlType.DIVIDLINE, icon: 'line', desc: '描述文字可以为表单添加段落说明信息，字体样式可自定义设置' },
      { title: T('adjustablePitch'), type: ControlType.ADJUSTSPACING, icon: 'blank' },
    ],
  },
  {
    title: T('scriptComponent'),
    children: [
      { title: 'before', icon: 'script', type: ControlType.SCRIPT_BEFORE },
      { title: 'load', icon: 'script', type: ControlType.SCRIPT_LOAD },
      { title: 'change', icon: 'script', type: ControlType.SCRIPT_CHANGE },
      { title: 'submit', icon: 'script', type: ControlType.SCRIPT_SUBMIT },
      { title: 'interceptors', icon: 'script', type: ControlType.SCRIPT_INTERCEPTORS }
    ]
  }
];

// 控件对应关系
export const controlMap = {
  [ControlType.INPUT]: Input,
  [ControlType.SCAN]: Scan,
  [ControlType.INPUT_NUMBER]: InputNumber,
  [ControlType.DATE_PICKER]: DatePicker,
  [ControlType.SELECT]: Select,
  [ControlType.RADIO]: Radio,
  [ControlType.TEXT]: Text,
  [ControlType.TEXT_AREA]: TextArea,
  [ControlType.CHECKBOX]: Checkbox,
  [ControlType.SWITCH]: Switch,
  [ControlType.UPLOAD]: Upload,
  [ControlType.TABLE]: Table,
  [ControlType.DIVIDLINE]: DividLine,
  [ControlType.ADJUSTSPACING]: AdjustSpacing,
  [ControlType.IMG]: Img,
  [ControlType.DATALINK]: DataLink,
  [ControlType.DATALINKCOMBOX]: DataLinkComBox,
  [ControlType.MEDIA]: Media,
  [ControlType.RICHTEXT]: RichText,
  [ControlType.SCRIPT_CHANGE]: ScriptChange,
  [ControlType.SCRIPT_LOAD]: ScriptLoad,
  [ControlType.SCRIPT_SUBMIT]: ScriptSubmit,
  [ControlType.ORDER_NUMBER]: OrderNumber,
  [ControlType.DATA_LIST]: DataList,
  [ControlType.BUTTON]: Button,
  [ControlType.CODE]: Code,
  [ControlType.MODELFORM]: () => null,
  [ControlType.TEMPLATE]: Template,
  [ControlType.SCRIPT_INTERCEPTORS]: ScriptInterceptors,
  [ControlType.ROW]: Row,
  [ControlType.COL]: Col,
  [ControlType.CHARTS]: Charts,
  [ControlType.TABS]: Tabs,
  [ControlType.SCRIPT_BEFORE]: ScriptBefore,
  [ControlType.COLLAPSE]: Collapse,
  [ControlType.TAG]: Tag
};

// 控制器对应关系
export const controllerMap = {
  [ControlType.INPUT]: InputController,
  [ControlType.SCAN]: ScanController,
  [ControlType.INPUT_NUMBER]: InputNumberController,
  [ControlType.DATE_PICKER]: DatePickerController,
  [ControlType.SELECT]: SelectController,
  [ControlType.RADIO]: RadioController,
  [ControlType.TEXT]: TextController,
  [ControlType.TEXT_AREA]: TextareaController,
  [ControlType.CHECKBOX]: CheckboxController,
  [ControlType.SWITCH]: SwitchControl,
  [ControlType.UPLOAD]: UploadController,
  [ControlType.TABLE]: TableController,
  [ControlType.DIVIDLINE]: DividLineController,
  [ControlType.ADJUSTSPACING]: AdjustSpacingController,
  [ControlType.IMG]: ImgController,
  [ControlType.DATALINK]: DataLinkController,
  [ControlType.DATALINKCOMBOX]: DataLinkComBoxController,
  [ControlType.MEDIA]: MediaController,
  [ControlType.RICHTEXT]: RichTextController,
  [ControlType.SCRIPT_CHANGE]: ScriptChangeController,
  [ControlType.SCRIPT_LOAD]: ScriptLoadController,
  [ControlType.SCRIPT_SUBMIT]: ScriptSubmitController,
  [ControlType.ORDER_NUMBER]: OrderNumberController,
  [ControlType.DATA_LIST]: DataListController,
  [ControlType.BUTTON]: ButtonController,
  [ControlType.CODE]: CodeController,
  [ControlType.MODELFORM]: () => null,
  [ControlType.TEMPLATE]: TemplateController,
  [ControlType.SCRIPT_INTERCEPTORS]: ScriptInterceptorsController,
  [ControlType.COL]: ColController,
  [ControlType.ROW]: RowController,
  [ControlType.CHARTS]: ChartsController,
  [ControlType.TABS]: TabsControl,
  [ControlType.SCRIPT_BEFORE]: ScriptBeforeController,
  [ControlType.COLLAPSE]: CollapseController,
  [ControlType.TAG]: TagController
};

const defDataSource = [
  { label: '未命名1', value: 'Value 1', key: uuidv4() },
  { label: '未命名2', value: 'Value 2', key: uuidv4() },
  { label: '未命名3', value: 'Value 3', key: uuidv4() },
];

const formItemDefStyle = {
  width: '100%',
};

const dividLineDefStyle = {
  width: '100%',
  marginTop: '16px',
  marginBottom: '16px',
};

const adjustDefStyle = {
  width: '100%',
  padding: '8px',
  height: '16px',
};

// 控件默认配置
export const controlDefOptions = {
  [ControlType.INPUT]: {
    formItemProps: {
      label: '输入框',
      style: formItemDefStyle,
    },
    inputProps: {
      placeholder: '请输入',
    },
  },
  [ControlType.SCAN]: {
    formItemProps: {
      label: '扫码框',
      style: formItemDefStyle,
    },
    scanProps: {
      placeholder: '请扫码',
    },
  },
  [ControlType.CODE]: {
    formItemProps: {
      label: '码',
      style: formItemDefStyle,
    },
    codeProps: {
      type: 'barCode',
      initialValue: 'we-linkin'
    },
  },
  [ControlType.CHARTS]: {
    formItemProps: {
      style: { ...formItemDefStyle, height: '400px' },
    },
    chartsProps: {
      query: '{"pages":{"pageSize":20,"page":1}}',
      type: 'line',
      url: '/bk/api/material/Material/find'
    },
  },
  [ControlType.INPUT_NUMBER]: {
    formItemProps: {
      label: '数字输入框',
      style: formItemDefStyle,
    },
  },
  [ControlType.DATE_PICKER]: {
    formItemProps: {
      label: '日期选择',
      style: formItemDefStyle,
    },
    datePickerProps: {
      format: 'YYYY/MM/DD',
      placeholder: '请选择',
    },
  },
  [ControlType.SELECT]: {
    formItemProps: {
      label: '下拉选择',
      style: formItemDefStyle,
    },
    selectProps: {
      dataSource: defDataSource,
      placeholder: '请选择',
    },
  },
  [ControlType.RADIO]: {
    formItemProps: {
      label: '单选按钮',
      style: formItemDefStyle,
    },
    radioProps: {
      dataSource: defDataSource,
    },
  },
  [ControlType.CHECKBOX]: {
    formItemProps: {
      label: '多选按钮',
      style: formItemDefStyle,
    },
    checkboxProps: {
      dataSource: defDataSource,
    },
  },
  [ControlType.TEXT]: {
    textProps: {
      text: '',
    },
    style: {
      fontSize: '14px',
      width: '100%',
    },
  },
  [ControlType.TEXT_AREA]: {
    formItemProps: {
      label: '多行文本',
      style: formItemDefStyle,
    },
    textAreaProps: {
      placeholder: '请输入',
    },
  },
  [ControlType.SWITCH]: {
    formItemProps: {
      label: '切换',
      style: formItemDefStyle,
    },
    switchProps: {

    }
  },
  [ControlType.UPLOAD]: {
    formItemProps: {
      label: '附件上传',
      style: formItemDefStyle,
    },
    uploadProps: {},
  },
  [ControlType.TABLE]: {
    name: '',
    tableProps: {
      columns: [],
      showItemNo: false,
      dataSource: [],
    },
    title: '表格标题',
    titleEn: '表格标题',
    type: ControlType.TABLE,
    style: { width: '100%' },
  },

  [ControlType.DIVIDLINE]: {
    formItemProps: {
      label: '',
      style: dividLineDefStyle,
    },
  },
  [ControlType.ADJUSTSPACING]: {
    formItemProps: {
      label: '',
      style: adjustDefStyle,
    },
  },
  [ControlType.IMG]: {
    formItemProps: {
      label: '',
      style: {
        width: 156,
        height: 88,
        minHeight: '20px',
        textAlign: 'left',
      },
    },
    imgProps: {
      url: '',
      rate: 1.78,
    },
  },
  [ControlType.DATALINK]: {
    formItemProps: {
      label: 'Lov关联',
      style: formItemDefStyle,
    },
    inputProps: {
      placeholder: '请选择',
      serviceType: 'APP',
      modulesUrl: '',
      serviceModuleCode: undefined,
      modulesName: undefined,
      fieldNames: undefined,
      showFieldName: undefined,
      line: {},
      screenCondition: [],
    },
  },
  [ControlType.DATALINKCOMBOX]: {
    formItemProps: {
      label: 'Combox关联',
      style: formItemDefStyle,
    },
    inputProps: {
      placeholder: '请选择',
      serviceType: 'APP',
      modulesUrl: '',
      serviceModuleCode: undefined,
      modulesName: undefined,
      fieldNames: [],
      showFieldName: undefined,
      line: {},
      screenCondition: [],
      screenConditionRules: [],
    },
  },
  [ControlType.MEDIA]: {
    formItemProps: {
      label: '多媒体',
      style: formItemDefStyle,
    },
    mediaProps: {},
  },
  [ControlType.RICHTEXT]: {
    formItemProps: {
      label: '富文本',
      style: formItemDefStyle,
    },
    richProps: {},
  },
  [ControlType.ORDER_NUMBER]: {
    formItemProps: {
      label: '流水编号',
      style: formItemDefStyle
    },
    orderNumberProps: {},
  },
  [ControlType.BUTTON]: {
    buttonProps: {
      text: '按钮'
    }
  },
  [ControlType.DATA_LIST]: {
    actionBtnGroup: [
      { text: '编辑', type: 'edit', scriptText: '', url: '', key: 'edit' },
      { text: '删除', type: 'delete', scriptText: '', url: '', key: 'delete' },
    ]
  },
  [ControlType.TEMPLATE]: {
    formItemProps: {
      label: '模板引擎',
      style: formItemDefStyle,
    },
    templateProps: {
      text: '',
    },
  },
  [ControlType.COL]: {
    colProps: {
      span: 6
    }
  },
  [ControlType.TABS]: {
    tabsProps: {
      tabs: [
        { value: 'Value 1', key: uuidv4(), label: '未命名1' },
        { value: 'Value 2', key: uuidv4(), label: '未命名2' }
      ]
    }
  }
};

// 改变项对应需要清除的数据 lov combox共用

export const ChangeForData = {
  serviceType: {
    serviceModuleCode: undefined,
    modulesName: undefined,
    fieldNames: undefined,
    filedShowName: undefined,
    modulesUrl: undefined,
    showFieldName: undefined,
    screenCondition: [],
    screenConditionRules: [],
  },
  serviceModuleCode: {
    modulesName: undefined,
    fieldNames: undefined,
    filedShowName: undefined,
    showFieldName: undefined,
    modulesUrl: undefined,
    screenCondition: [],
    screenConditionRules: [],
  },
  modulesUrl: {
    filedShowName: undefined,
    showFieldName: undefined,
    screenCondition: [],
    screenConditionRules: [],
  },
  modulesName: {
    filedShowName: undefined,
    screenCondition: [],
    screenConditionRules: [],
    showFieldName: undefined,
  },
};

// input正则
export const regExpSource = [
  { id: '1', label: '字母或数字', value: 'letterNumbersPattern' },
  { id: '2', label: '邮箱', value: 'mailPattern' },
  { id: '3', label: '手机', value: 'phonePattern' },
  { id: '4', label: '电话号码', value: 'telPattern' },
  { id: '5', label: '身份证', value: 'idNumberPattern' },
];

export const regExpPatterns = {
  letterNumbersPattern: {
    pattern: new RegExp('^[a-zA-Z0-9]+$'),
    message: '只能输入字母或数字'
  },
  mailPattern: {
    pattern: new RegExp('^([a-zA-Z]|[0-9])(\\w|\\-)+@[a-zA-Z0-9]+\\.([a-zA-Z]{2,4})$'),
    message: '邮箱格式不正确'
  },
  phonePattern: {
    pattern: new RegExp('^1[3456789]\\d{9}$'),
    message: '手机格式不正确'
  },
  telPattern: {
    pattern: new RegExp('^(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{7,14}$'),
    message: '电话号码不正确'
  },
  idNumberPattern: {
    pattern: /^(\d{18}|\d{15}|\d{17}x)$/,
    message: '身份证号码不正确'
  }
};

